//
//  SecondViewController.m
//  changeViewController
//
//  Created by marcus wang on 12-1-11.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "SecondViewController.h"
#import "Config.h"
#import "Utility.h"
#import "SecondViewCell.h"

@implementation SecondViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.view.backgroundColor=[UIColor clearColor];
       
        // Custom initialization
    }
    return self;
}



#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    float height=367;
    if (iPhone5) {
        height+=88;
    }
    self.view.frame=CGRectMake(0, 0, self.view.frame.size.width, height);
    // Do any additional setup after loading the view from its nib.
    self.mytableView=[[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, height) style:UITableViewStylePlain];
    self.mytableView.separatorStyle=UITableViewCellSeparatorStyleSingleLine;
    self.mytableView.delegate=self;
    self.mytableView.dataSource=self;
    [self.view addSubview:self.mytableView];
    self.arrayList=[NSMutableArray array];
    [self.arrayList addObjectsFromArray:@[@"1",@"2",@"1",@"2",@"1",@"2",@"2",@"1",@"2"]];
    [self.mytableView reloadData];
}

//表视图委托
#pragma mark -
#pragma mark table view data source methods

//返回某个表视图有多少行数据
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return [self.arrayList count];
}

//设置行高度
- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [self tableView:tableView cellForRowAtIndexPath:indexPath];
    return cell.frame.size.height;
}


//表视图显示表视图项时调用：第一次显示（根据视图大小显示多少个视图项就调用多少次）以及拖动时调用
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    static NSString *CellIdentifier = @"secondViewCell";
    
    SecondViewCell *cell =(SecondViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[SecondViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                       reuseIdentifier: CellIdentifier];
    }
    UIFont *font=[UIFont fontWithName:FONT_FAMILY size:12.0f];
    NSString *content=@"你到时候等通知把，我线书叫了";
    CGSize size=[Utility getStringSize:content font:font withMaxSize:CGSizeMake(225, 100)];
    cell.frame=CGRectMake(0, 0, self.view.frame.size.width, 50+size.height);
    CGRect rect=cell.content.frame;
    cell.content.numberOfLines=size.height/17;
    rect.size.height=size.height;
    cell.content.frame=rect;
     cell.detailTitle.frame=CGRectMake(62, cell.frame.size.height-24, 220, 12);
    
    
    cell.logo.image=[Utility imageNamed:@"cg_logo.png"];
    cell.nickname.text=@"云吞";
    cell.content.text=content;
    cell.detailTitle.text=[NSString stringWithFormat:@"%@",@"2013-4-19"];
    return cell;
}



//某行已经被选中时调用
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
}


- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
